<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" type="text/css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="./resources/prism/prism.css" type="text/css">
    <link rel="stylesheet" href="../css/ol.css" type="text/css">
    <link rel="stylesheet" href="./resources/layout.css" type="text/css">
    
    
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script>
    <title>Marker Animation</title>
  </head>
  <body>

    <header class="navbar" role="navigation">
      <div class="container">
        <div class="display-table pull-left" id="navbar-logo-container">
          <a class="navbar-brand" href="./"><img src="./resources/logo-70x70.png">&nbsp;OpenLayers Examples</a>
        </div>
        <!-- menu items that get hidden below 768px width -->
        <nav class='collapse navbar-collapse navbar-responsive-collapse'>
          <ul class="nav navbar-nav pull-right">
            <li><a href="../doc">Docs</a></li>
            <li><a class="active" href="index.html">Examples</a></li>
            <li><a href="../apidoc">API</a></li>
            <li><a href="https://github.com/openlayers/openlayers">Code</a></li>
          </ul>
        </nav>
      </div>
    </header>

    <div class="container-fluid">

      <div id="latest-check" class="alert alert-warning alert-dismissible" role="alert" style="display:none">
        <button id="latest-dismiss" type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        This example uses OpenLayers v<span>4.6.5</span>. The <a id="latest-link" href="#" class="alert-link">latest</a> is v<span id="latest-version"></span>.
      </div>

      <div class="row-fluid">
        <div class="span12">
          <h4 id="title">Marker Animation</h4>
          <div id="map" class="map"></div>
<label for="speed">
  speed:&nbsp;
  <input id="speed" type="range" min="10" max="999" step="10" value="60">
</label>
<button id="start-animation">Start Animation</button>

        </div>
      </div>

      <div class="row-fluid">
        <div class="span12">
          <p id="shortdesc">Demonstrates how to move a feature along a line.</p>
          <div id="docs"><p>This example shows how to use <b>postcompose</b> and <b>vectorContext</b> to animate a (marker) feature along a line. In this example an encoded polyline is being used.</p>
</div>
          <div id="api-links">Related API documentation: <ul class="inline"><li><a href="../apidoc/ol.Feature.html" title="API documentation for ol.Feature">ol.Feature</a></li>,<li><a href="../apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map</a></li>,<li><a href="../apidoc/ol.View.html" title="API documentation for ol.View">ol.View</a></li>,<li><a href="../apidoc/ol.format.Polyline.html" title="API documentation for ol.format.Polyline">ol.format.Polyline</a></li>,<li><a href="../apidoc/ol.geom.Point.html" title="API documentation for ol.geom.Point">ol.geom.Point</a></li>,<li><a href="../apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile</a></li>,<li><a href="../apidoc/ol.layer.Vector.html" title="API documentation for ol.layer.Vector">ol.layer.Vector</a></li>,<li><a href="../apidoc/ol.source.BingMaps.html" title="API documentation for ol.source.BingMaps">ol.source.BingMaps</a></li>,<li><a href="../apidoc/ol.source.Vector.html" title="API documentation for ol.source.Vector">ol.source.Vector</a></li>,<li><a href="../apidoc/ol.style.Circle.html" title="API documentation for ol.style.Circle">ol.style.Circle</a></li>,<li><a href="../apidoc/ol.style.Fill.html" title="API documentation for ol.style.Fill">ol.style.Fill</a></li>,<li><a href="../apidoc/ol.style.Icon.html" title="API documentation for ol.style.Icon">ol.style.Icon</a></li>,<li><a href="../apidoc/ol.style.Stroke.html" title="API documentation for ol.style.Stroke">ol.style.Stroke</a></li>,<li><a href="../apidoc/ol.style.Style.html" title="API documentation for ol.style.Style">ol.style.Style</a></li></ul></div>
        </div>
      </div>

      <div class="row-fluid">
        <div id="source-controls">
          <a id="copy-button"><i class="fa fa-clipboard"></i> Copy</a>
          <a id="codepen-button"><i class="fa fa-codepen"></i> Edit</a>
        </div>
        <form method="POST" id="codepen-form" target="_blank" action="https://codepen.io/pen/define/">
          <textarea class="hidden" name="title">Marker Animation</textarea>
          <textarea class="hidden" name="description">Demonstrates how to move a feature along a line.</textarea>
          <textarea class="hidden" name="js">// This long string is placed here due to jsFiddle limitations.
// It is usually loaded with AJAX.
var polyline &#x3D; [
  &#x27;hldhx@lnau&#x60;BCG_EaC??cFjAwDjF??uBlKMd@}@z@??aC^yk@z_@se@b[wFdE??wFfE}N&#x27;,
  &#x27;fIoGxB_I\\gG}@eHoCyTmPqGaBaHOoD\\??yVrGotA|N??o[N_STiwAtEmHGeHcAkiA}^&#x27;,
  &#x27;aMyBiHOkFNoI&#x60;CcVvM??gG^gF_@iJwC??eCcA]OoL}DwFyCaCgCcCwDcGwHsSoX??wI_E&#x27;,
  &#x27;kUFmq@hBiOqBgTwS??iYse@gYq\\cp@ce@{vA}s@csJqaE}{@iRaqE{lBeRoIwd@_T{]_&#x27;,
  &#x27;Ngn@{PmhEwaA{SeF_u@kQuyAw]wQeEgtAsZ}LiCarAkVwI}D??_}RcjEinPspDwSqCgs@&#x27;,
  &#x27;sPua@_OkXaMeT_Nwk@ob@gV}TiYs[uTwXoNmT{Uyb@wNg]{Nqa@oDgNeJu_@_G}YsFw]k&#x27;,
  &#x27;DuZyDmm@i_@uyIJe~@jCg|@nGiv@zUi_BfNqaAvIow@dEed@dCcf@r@qz@Egs@{Acu@mC&#x27;,
  &#x27;um@yIey@gGig@cK_m@aSku@qRil@we@{mAeTej@}Tkz@cLgr@aHko@qOmcEaJw~C{w@ka&#x27;,
  &#x27;i@qBchBq@kmBS{kDnBscBnFu_Dbc@_~QHeU&#x60;IuyDrC_}@bByp@fCyoA?qMbD}{AIkeAgB&#x27;,
  &#x27;k_A_A{UsDke@gFej@qH{o@qGgb@qH{&#x60;@mMgm@uQus@kL{_@yOmd@ymBgwE}x@ouBwtA__&#x27;,
  &#x27;DuhEgaKuWct@gp@cnBii@mlBa_@}|Asj@qrCg^eaC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#x27;ab@&#x60;CuOlC}YnAcV&#x60;@_^m@aeB}@yk@YuTuBg^uCkZiGk\\yGeY}Lu_@oOsZiTe[uWi[sl@&#x27;,
  &#x27;mo@soAauAsrBgzBqgAglAyd@ig@asAcyAklA}qAwHkGi{@s~@goAmsAyDeEirB_{B}IsJ&#x27;,
  &#x27;uEeFymAssAkdAmhAyTcVkFeEoKiH}l@kp@wg@sj@ku@ey@uh@kj@}EsFmG}Jk^_r@_f@m&#x27;,
  &#x27;~@ym@yjA??a@cFd@kBrCgDbAUnAcBhAyAdk@et@??kF}D??OL&#x27;
].join(&#x27;&#x27;);

var route &#x3D; /** @type {ol.geom.LineString} */ (new ol.format.Polyline({
  factor: 1e6
}).readGeometry(polyline, {
  dataProjection: &#x27;EPSG:4326&#x27;,
  featureProjection: &#x27;EPSG:3857&#x27;
}));

var routeCoords &#x3D; route.getCoordinates();
var routeLength &#x3D; routeCoords.length;

var routeFeature &#x3D; new ol.Feature({
  type: &#x27;route&#x27;,
  geometry: route
});
var geoMarker &#x3D; new ol.Feature({
  type: &#x27;geoMarker&#x27;,
  geometry: new ol.geom.Point(routeCoords[0])
});
var startMarker &#x3D; new ol.Feature({
  type: &#x27;icon&#x27;,
  geometry: new ol.geom.Point(routeCoords[0])
});
var endMarker &#x3D; new ol.Feature({
  type: &#x27;icon&#x27;,
  geometry: new ol.geom.Point(routeCoords[routeLength - 1])
});

var styles &#x3D; {
  &#x27;route&#x27;: new ol.style.Style({
    stroke: new ol.style.Stroke({
      width: 6, color: [237, 212, 0, 0.8]
    })
  }),
  &#x27;icon&#x27;: new ol.style.Style({
    image: new ol.style.Icon({
      anchor: [0.5, 1],
      src: &#x27;https://openlayers.org/en/v4.6.5/examples/data/icon.png&#x27;
    })
  }),
  &#x27;geoMarker&#x27;: new ol.style.Style({
    image: new ol.style.Circle({
      radius: 7,
      snapToPixel: false,
      fill: new ol.style.Fill({color: &#x27;black&#x27;}),
      stroke: new ol.style.Stroke({
        color: &#x27;white&#x27;, width: 2
      })
    })
  })
};

var animating &#x3D; false;
var speed, now;
var speedInput &#x3D; document.getElementById(&#x27;speed&#x27;);
var startButton &#x3D; document.getElementById(&#x27;start-animation&#x27;);

var vectorLayer &#x3D; new ol.layer.Vector({
  source: new ol.source.Vector({
    features: [routeFeature, geoMarker, startMarker, endMarker]
  }),
  style: function(feature) {
    // hide geoMarker if animation is active
    if (animating &amp;&amp; feature.get(&#x27;type&#x27;) &#x3D;&#x3D;&#x3D; &#x27;geoMarker&#x27;) {
      return null;
    }
    return styles[feature.get(&#x27;type&#x27;)];
  }
});

var center &#x3D; [-5639523.95, -3501274.52];
var map &#x3D; new ol.Map({
  target: document.getElementById(&#x27;map&#x27;),
  loadTilesWhileAnimating: true,
  view: new ol.View({
    center: center,
    zoom: 10,
    minZoom: 2,
    maxZoom: 19
  }),
  layers: [
    new ol.layer.Tile({
      source: new ol.source.BingMaps({
        imagerySet: &#x27;AerialWithLabels&#x27;,
        key: &#x27;Your Bing Maps Key from http://www.bingmapsportal.com/ here&#x27;
      })
    }),
    vectorLayer
  ]
});

var moveFeature &#x3D; function(event) {
  var vectorContext &#x3D; event.vectorContext;
  var frameState &#x3D; event.frameState;

  if (animating) {
    var elapsedTime &#x3D; frameState.time - now;
    // here the trick to increase speed is to jump some indexes
    // on lineString coordinates
    var index &#x3D; Math.round(speed * elapsedTime / 1000);

    if (index &gt;&#x3D; routeLength) {
      stopAnimation(true);
      return;
    }

    var currentPoint &#x3D; new ol.geom.Point(routeCoords[index]);
    var feature &#x3D; new ol.Feature(currentPoint);
    vectorContext.drawFeature(feature, styles.geoMarker);
  }
  // tell OpenLayers to continue the postcompose animation
  map.render();
};

function startAnimation() {
  if (animating) {
    stopAnimation(false);
  } else {
    animating &#x3D; true;
    now &#x3D; new Date().getTime();
    speed &#x3D; speedInput.value;
    startButton.textContent &#x3D; &#x27;Cancel Animation&#x27;;
    // hide geoMarker
    geoMarker.setStyle(null);
    // just in case you pan somewhere else
    map.getView().setCenter(center);
    map.on(&#x27;postcompose&#x27;, moveFeature);
    map.render();
  }
}


/**
 * @param {boolean} ended end of animation.
 */
function stopAnimation(ended) {
  animating &#x3D; false;
  startButton.textContent &#x3D; &#x27;Start Animation&#x27;;

  // if animation cancelled set the marker at the beginning
  var coord &#x3D; ended ? routeCoords[routeLength - 1] : routeCoords[0];
  /** @type {ol.geom.Point} */ (geoMarker.getGeometry())
      .setCoordinates(coord);
  //remove listener
  map.un(&#x27;postcompose&#x27;, moveFeature);
}

startButton.addEventListener(&#x27;click&#x27;, startAnimation, false);
</textarea>
          <textarea class="hidden" name="css"></textarea>
          <textarea class="hidden" name="html">&lt;div id&#x3D;&quot;map&quot; class&#x3D;&quot;map&quot;&gt;&lt;/div&gt;
&lt;label for&#x3D;&quot;speed&quot;&gt;
  speed:&amp;nbsp;
  &lt;input id&#x3D;&quot;speed&quot; type&#x3D;&quot;range&quot; min&#x3D;&quot;10&quot; max&#x3D;&quot;999&quot; step&#x3D;&quot;10&quot; value&#x3D;&quot;60&quot;&gt;
&lt;/label&gt;
&lt;button id&#x3D;&quot;start-animation&quot;&gt;Start Animation&lt;/button&gt;
</textarea>
          <input type="hidden" name="resources" value="https://openlayers.org/en/v4.6.5/css/ol.css,https://openlayers.org/en/v4.6.5/build/ol.js">
          <input type="hidden" name="data">
        </form>
        <pre><code id="example-source" class="language-markup">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Marker Animation&lt;/title&gt;
    &lt;link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css"&gt;
    &lt;!-- The line below is only needed for old environments like Internet Explorer and Android 4.x --&gt;
    &lt;script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"&gt;&lt;/script&gt;
    &lt;script src="https://openlayers.org/en/v4.6.5/build/ol.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id&#x3D;&quot;map&quot; class&#x3D;&quot;map&quot;&gt;&lt;/div&gt;
    &lt;label for&#x3D;&quot;speed&quot;&gt;
      speed:&amp;nbsp;
      &lt;input id&#x3D;&quot;speed&quot; type&#x3D;&quot;range&quot; min&#x3D;&quot;10&quot; max&#x3D;&quot;999&quot; step&#x3D;&quot;10&quot; value&#x3D;&quot;60&quot;&gt;
    &lt;/label&gt;
    &lt;button id&#x3D;&quot;start-animation&quot;&gt;Start Animation&lt;/button&gt;
    &lt;script&gt;
      // This long string is placed here due to jsFiddle limitations.
      // It is usually loaded with AJAX.
      var polyline &#x3D; [
        &#x27;hldhx@lnau&#x60;BCG_EaC??cFjAwDjF??uBlKMd@}@z@??aC^yk@z_@se@b[wFdE??wFfE}N&#x27;,
        &#x27;fIoGxB_I\\gG}@eHoCyTmPqGaBaHOoD\\??yVrGotA|N??o[N_STiwAtEmHGeHcAkiA}^&#x27;,
        &#x27;aMyBiHOkFNoI&#x60;CcVvM??gG^gF_@iJwC??eCcA]OoL}DwFyCaCgCcCwDcGwHsSoX??wI_E&#x27;,
        &#x27;kUFmq@hBiOqBgTwS??iYse@gYq\\cp@ce@{vA}s@csJqaE}{@iRaqE{lBeRoIwd@_T{]_&#x27;,
        &#x27;Ngn@{PmhEwaA{SeF_u@kQuyAw]wQeEgtAsZ}LiCarAkVwI}D??_}RcjEinPspDwSqCgs@&#x27;,
        &#x27;sPua@_OkXaMeT_Nwk@ob@gV}TiYs[uTwXoNmT{Uyb@wNg]{Nqa@oDgNeJu_@_G}YsFw]k&#x27;,
        &#x27;DuZyDmm@i_@uyIJe~@jCg|@nGiv@zUi_BfNqaAvIow@dEed@dCcf@r@qz@Egs@{Acu@mC&#x27;,
        &#x27;um@yIey@gGig@cK_m@aSku@qRil@we@{mAeTej@}Tkz@cLgr@aHko@qOmcEaJw~C{w@ka&#x27;,
        &#x27;i@qBchBq@kmBS{kDnBscBnFu_Dbc@_~QHeU&#x60;IuyDrC_}@bByp@fCyoA?qMbD}{AIkeAgB&#x27;,
        &#x27;k_A_A{UsDke@gFej@qH{o@qGgb@qH{&#x60;@mMgm@uQus@kL{_@yOmd@ymBgwE}x@ouBwtA__&#x27;,
        &#x27;DuhEgaKuWct@gp@cnBii@mlBa_@}|Asj@qrCg^eaC}L{dAaJ_aAiOyjByH{nAuYu&#x60;GsAw&#x27;,
        &#x27;Xyn@ywMyOyqD{_@cfIcDe}@y@aeBJmwA&#x60;CkiAbFkhBlTgdDdPyiB&#x60;W}xDnSa}DbJyhCrX&#x27;,
        &#x27;itAhT}x@bE}Z_@qW_Kwv@qKaaAiBgXvIm}A~JovAxCqW~WanB&#x60;XewBbK{_A&#x60;K}fBvAmi@&#x27;,
        &#x27;xBycBeCauBoF}}@qJioAww@gjHaPopA_NurAyJku@uGmi@cDs[eRaiBkQstAsQkcByNma&#x27;,
        &#x27;CsK_uBcJgbEw@gkB_@ypEqDoqSm@eZcDwjBoGw&#x60;BoMegBaU_&#x60;Ce_@_uBqb@ytBwkFqiT_&#x27;,
        &#x27;fAqfEwe@mfCka@_eC_UmlB}MmaBeWkkDeHwqAoX}~DcBsZmLcxBqOwqE_DkyAuJmrJ\\o&#x27;,
        &#x27;~CfIewG|YibQxBssB?es@qGciA}RorAoVajA_nAodD{[y&#x60;AgPqp@mKwr@ms@umEaW{dAm&#x27;,
        &#x27;b@umAw|@ojBwzDaaJsmBwbEgdCsrFqhAihDquAi&#x60;Fux@}_Dui@_eB_u@guCuyAuiHukA_&#x27;,
        &#x27;lKszAu|OmaA{wKm}@clHs_A_rEahCssKo\\sgBsSglAqk@yvDcS_wAyTwpBmPc|BwZknF&#x27;,
        &#x27;oFscB_GsaDiZmyMyLgtHgQonHqT{hKaPg}Dqq@m~Hym@c&#x60;EuiBudIabB{hF{pWifx@snA&#x27;,
        &#x27;w&#x60;GkFyVqf@y~BkoAi}Lel@wtc@}&#x60;@oaXi_C}pZsi@eqGsSuqJ|Lqeb@e]kgPcaAu}SkDw&#x27;,
        &#x27;zGhn@gjYh\\qlNZovJieBqja@ed@siO{[ol\\kCmjMe\\isHorCmec@uLebB}EqiBaCg}&#x27;,
        &#x27;@m@qwHrT_vFps@kkI&#x60;uAszIrpHuzYxx@e{Crw@kpDhN{wBtQarDy@knFgP_yCu\\wyCwy&#x27;,
        &#x27;A{kHo~@omEoYmoDaEcPiuAosDagD}rO{{AsyEihCayFilLaiUqm@_bAumFo}DgqA_uByi&#x27;,
        &#x27;@swC~AkzDlhA}xEvcBa}Cxk@ql@&#x60;rAo|@~bBq{@&#x60;&#x60;Bye@djDww@z_C_cAtn@ye@nfC_eC&#x27;,
        &#x27;|gGahH~s@w}@&#x60;&#x60;Fi~FpnAooC|u@wlEaEedRlYkrPvKerBfYs}Arg@m}AtrCkzElw@gjBb&#x27;,
        &#x27;h@woBhR{gCwGkgCc[wtCuOapAcFoh@uBy[yBgr@c@iq@o@wvEv@sp@&#x60;FajBfCaq@fIipA&#x27;,
        &#x27;dy@ewJlUc&#x60;ExGuaBdEmbBpBssArAuqBBg}@s@g{AkB{bBif@_bYmC}r@kDgm@sPq_BuJ_&#x27;,
        &#x27;s@{X_{AsK_d@eM{d@wVgx@oWcu@??aDmOkNia@wFoSmDyMyCkPiBePwAob@XcQ|@oNdCo&#x27;,
        &#x27;SfFwXhEmOnLi\\lbAulB&#x60;X_d@|k@au@bc@oc@bqC}{BhwDgcD&#x60;l@ed@??bL{G|a@eTje@&#x27;,
        &#x27;oS~]cLr~Bgh@|b@}Jv}EieAlv@sPluD{z@nzA_]&#x60;|KchCtd@sPvb@wSb{@ko@f&#x60;RooQ~e&#x27;,
        &#x27;[upZbuIolI|gFafFzu@iq@nMmJ|OeJn^{Qjh@yQhc@uJ~j@iGdd@kAp~BkBxO{@|QsAfY&#x27;,
        &#x27;gEtYiGd]}Jpd@wRhVoNzNeK&#x60;j@ce@vgK}cJnSoSzQkVvUm^rSgc@&#x60;Uql@xIq\\vIgg@~k&#x27;,
        &#x27;Dyq[nIir@jNoq@xNwc@fYik@tk@su@neB}uBhqEesFjoGeyHtCoD|D}Ed|@ctAbIuOzqB&#x27;,
        &#x27;_}D~NgY&#x60;\\um@v[gm@v{Cw&#x60;G&#x60;w@o{AdjAwzBh{C}&#x60;Gpp@ypAxn@}mAfz@{bBbNia@??jI&#x27;,
        &#x27;ab@&#x60;CuOlC}YnAcV&#x60;@_^m@aeB}@yk@YuTuBg^uCkZiGk\\yGeY}Lu_@oOsZiTe[uWi[sl@&#x27;,
        &#x27;mo@soAauAsrBgzBqgAglAyd@ig@asAcyAklA}qAwHkGi{@s~@goAmsAyDeEirB_{B}IsJ&#x27;,
        &#x27;uEeFymAssAkdAmhAyTcVkFeEoKiH}l@kp@wg@sj@ku@ey@uh@kj@}EsFmG}Jk^_r@_f@m&#x27;,
        &#x27;~@ym@yjA??a@cFd@kBrCgDbAUnAcBhAyAdk@et@??kF}D??OL&#x27;
      ].join(&#x27;&#x27;);

      var route &#x3D; /** @type {ol.geom.LineString} */ (new ol.format.Polyline({
        factor: 1e6
      }).readGeometry(polyline, {
        dataProjection: &#x27;EPSG:4326&#x27;,
        featureProjection: &#x27;EPSG:3857&#x27;
      }));

      var routeCoords &#x3D; route.getCoordinates();
      var routeLength &#x3D; routeCoords.length;

      var routeFeature &#x3D; new ol.Feature({
        type: &#x27;route&#x27;,
        geometry: route
      });
      var geoMarker &#x3D; new ol.Feature({
        type: &#x27;geoMarker&#x27;,
        geometry: new ol.geom.Point(routeCoords[0])
      });
      var startMarker &#x3D; new ol.Feature({
        type: &#x27;icon&#x27;,
        geometry: new ol.geom.Point(routeCoords[0])
      });
      var endMarker &#x3D; new ol.Feature({
        type: &#x27;icon&#x27;,
        geometry: new ol.geom.Point(routeCoords[routeLength - 1])
      });

      var styles &#x3D; {
        &#x27;route&#x27;: new ol.style.Style({
          stroke: new ol.style.Stroke({
            width: 6, color: [237, 212, 0, 0.8]
          })
        }),
        &#x27;icon&#x27;: new ol.style.Style({
          image: new ol.style.Icon({
            anchor: [0.5, 1],
            src: &#x27;https://openlayers.org/en/v4.6.5/examples/data/icon.png&#x27;
          })
        }),
        &#x27;geoMarker&#x27;: new ol.style.Style({
          image: new ol.style.Circle({
            radius: 7,
            snapToPixel: false,
            fill: new ol.style.Fill({color: &#x27;black&#x27;}),
            stroke: new ol.style.Stroke({
              color: &#x27;white&#x27;, width: 2
            })
          })
        })
      };

      var animating &#x3D; false;
      var speed, now;
      var speedInput &#x3D; document.getElementById(&#x27;speed&#x27;);
      var startButton &#x3D; document.getElementById(&#x27;start-animation&#x27;);

      var vectorLayer &#x3D; new ol.layer.Vector({
        source: new ol.source.Vector({
          features: [routeFeature, geoMarker, startMarker, endMarker]
        }),
        style: function(feature) {
          // hide geoMarker if animation is active
          if (animating &amp;&amp; feature.get(&#x27;type&#x27;) &#x3D;&#x3D;&#x3D; &#x27;geoMarker&#x27;) {
            return null;
          }
          return styles[feature.get(&#x27;type&#x27;)];
        }
      });

      var center &#x3D; [-5639523.95, -3501274.52];
      var map &#x3D; new ol.Map({
        target: document.getElementById(&#x27;map&#x27;),
        loadTilesWhileAnimating: true,
        view: new ol.View({
          center: center,
          zoom: 10,
          minZoom: 2,
          maxZoom: 19
        }),
        layers: [
          new ol.layer.Tile({
            source: new ol.source.BingMaps({
              imagerySet: &#x27;AerialWithLabels&#x27;,
              key: &#x27;Your Bing Maps Key from http://www.bingmapsportal.com/ here&#x27;
            })
          }),
          vectorLayer
        ]
      });

      var moveFeature &#x3D; function(event) {
        var vectorContext &#x3D; event.vectorContext;
        var frameState &#x3D; event.frameState;

        if (animating) {
          var elapsedTime &#x3D; frameState.time - now;
          // here the trick to increase speed is to jump some indexes
          // on lineString coordinates
          var index &#x3D; Math.round(speed * elapsedTime / 1000);

          if (index &gt;&#x3D; routeLength) {
            stopAnimation(true);
            return;
          }

          var currentPoint &#x3D; new ol.geom.Point(routeCoords[index]);
          var feature &#x3D; new ol.Feature(currentPoint);
          vectorContext.drawFeature(feature, styles.geoMarker);
        }
        // tell OpenLayers to continue the postcompose animation
        map.render();
      };

      function startAnimation() {
        if (animating) {
          stopAnimation(false);
        } else {
          animating &#x3D; true;
          now &#x3D; new Date().getTime();
          speed &#x3D; speedInput.value;
          startButton.textContent &#x3D; &#x27;Cancel Animation&#x27;;
          // hide geoMarker
          geoMarker.setStyle(null);
          // just in case you pan somewhere else
          map.getView().setCenter(center);
          map.on(&#x27;postcompose&#x27;, moveFeature);
          map.render();
        }
      }


      /**
       * @param {boolean} ended end of animation.
       */
      function stopAnimation(ended) {
        animating &#x3D; false;
        startButton.textContent &#x3D; &#x27;Start Animation&#x27;;

        // if animation cancelled set the marker at the beginning
        var coord &#x3D; ended ? routeCoords[routeLength - 1] : routeCoords[0];
        /** @type {ol.geom.Point} */ (geoMarker.getGeometry())
            .setCoordinates(coord);
        //remove listener
        map.un(&#x27;postcompose&#x27;, moveFeature);
      }

      startButton.addEventListener(&#x27;click&#x27;, startAnimation, false);
    &lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;</code></pre>
      </div>
    </div>

    <script src="./resources/common.js"></script>
    <script src="./resources/prism/prism.min.js"></script>
    <script src="loader.js?id=feature-move-animation"></script>
  </body>
  <script>
  var packageUrl = 'https://raw.githubusercontent.com/openlayers/openlayers.github.io/build/package.json';
  fetch(packageUrl).then(function(response) {
    return response.json();
  }).then(function(json) {
    var latestVersion = json.version;
    document.getElementById('latest-version').innerHTML = latestVersion;
    var url = window.location.href;
    var branchSearch = url.match(/\/([^\/]*)\/examples\//);
    var cookieText = 'dismissed=-' + latestVersion + '-';
    var dismissed = document.cookie.indexOf(cookieText) != -1;
    if (!dismissed && /^v[0-9\.]*$/.test(branchSearch[1]) && '4.6.5' != latestVersion) {
      var link = url.replace(branchSearch[0], '/latest/examples/');
      fetch(link, {method: 'head'}).then(function(response) {
        var a = document.getElementById('latest-link');
        a.href = response.status == 200 ? link : '../../latest/examples/';
      });
      var latestCheck = document.getElementById('latest-check');
      latestCheck.style.display = '';
      document.getElementById('latest-dismiss').onclick = function() {
        latestCheck.style.display = 'none';
        document.cookie = cookieText;
      }
    }
  });
  </script>
</html>
